package main.java.game.command;


import java.util.List;
import java.util.Random;

import main.java.game.Battle;
import main.java.game.Card;
import main.java.game.Game;
import main.java.game.item.Treasure;

/**
 * @author  ILDiNHo
 */
public class RetreatBattle implements BattleCommand {

	/**
	 * @uml.property  name="battle"
	 * @uml.associationEnd  
	 */
	private Battle battle;
	private Game game;
	public RetreatBattle(Battle battle, Game game){
		this.battle=battle;
		this.game = game;
	}
	
	public void execute() {
	
		battle.getPlayer().setGold(battle.getPlayer().getGold()-battle.getMonster().getWithdrawalPrice());
		if(battle.getMonster().getName().equals("Le Tarasque")){
			Random random=new Random();
			List<Treasure> lt=game.getPlayer().getTreasures();
			Integer index = Math.abs(random.nextInt()%lt.size());
			lt.remove(index);
		}
		List<Card> discard=game.getDiscardPile();
		discard.add(battle.getMonster());
		battle.changeCancelledBattle(true);
		
		 

	}
	public Battle getAssociatedBattle(){
		return battle;
	}

}
